#include <CODEPORTS/codeports.h>
#include <stdlib.h>

int
main(int argc, char **argv)
{
	DEMO demo;
	BOX box;
	PLUGIN plugin;
	int w, h, div, move, x, y;

	CP_Init();
	SCR_GetSize(&w, &h);
	PL_Load(&plugin, argv[1]);

	div = argc < 3 ? 1 : atoi(argv[2]);
	move = argc < 4 ? (div > 1) : atoi(argv[3]);
	BOX_Allocate(&box, w / div, h / div);
	plugin.DEMO_Init(&demo, &box);

	for(x = (w - box.info.width) / 2, y = (h - box.info.height) / 2; !KEY_Update(); x += move ? rand() % 10 - 5 : 0, y += move ? rand() % 10 - 5 : 0)
    	{
		SWP_Clear();

		BOX_Clear(demo.box);
		plugin.DEMO_Frame(&demo);
		SWP_SetBox(x % w, y % h, demo.box);
		SWP_Screen();
	}

	plugin.DEMO_Final(&demo);
	BOX_Free(demo.box);

	PL_Unload(&plugin);
	//SCR_Clear();
	CP_Final();

	return EXIT_SUCCESS;
}
